new Vue({
    el: '#app',
    data() {
        return {
            loading:false,
            html: '',
            options: [{
                value: 0,
                label: '用户服务协议'
            }, {
                value: 1,
                label: '用户授权协议'
            }, {
                value: 2,
                label: '用户隐私协议'
            }],
            form: {
                Agreement_SerialNumber: "",
                Agreement_Name: '',
                Agreement_Main: '',
                Agreement_Type: '',
            }
        }
    },
    mounted() {
        this.getNews()
    },
    methods: {
        getNews() {
            const { createEditor, createToolbar } = window.wangEditor
            const this_ = this
            const editorConfig = {
                placeholder: '协议内容',
                onChange(editor) {
                    this_.html = editor.getHtml()
                    console.log(this_.html)
                    // 也可以同步到 <textarea>
                }
            }
            const editor = createEditor({
                selector: '#editor-container',
                html: '<p><br></p>',
                config: editorConfig,
                mode: 'simple', // or 'simple'
            })

            const toolbarConfig = {}

            const toolbar = createToolbar({
                editor,
                selector: '#toolbar-container',
                config: toolbarConfig,
                mode: 'default', // or 'simple'
            })
        },
        back() {
            window.history.go(-1)
        },
        subMessage() {
            console.log(this.html)
            if (this.html == '') {
                this.$message.error("请输入协议标题")
                return
            }
            this.loading = true
            this.form.Agreement_Main = this.html
            const _this = this
            console.log(this.form)
            $.ajax({
                url: DomainName + '/GoodsFileAdd',
                type: 'POST',
                data: {
                    Data: JSON.stringify({
                        agreement_info: [_this.form]
                    }),
                    token: $.cookie("token")
                },
                success: function (res) {
                    console.log('提交结果', res)
                    if (res.Status == 'success') {
                        _this.loading = false
                        _this.$message.success("发布成功!")
                        window.history.go(-1)
                    }
                },
                error: function () {
                    _this.$message.error("操作失败，请稍后再试")
                },
                complete: function (XMLHttpRequest) {
                    _this.loading = false
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                }
            })
        }
    },
})